var empcode = $.getUrlParam('UserID');
window.onload = function() {
	$("#pwd-input").focus();
	$(".pwd-box").click(function() {
		$("#pwd-input").focus();
	});
	$("#goMessage").click(submit_verify);
	$("#btn").click(gotosure);
	var $input = $(".fake-box_change input");
	$("#pwd-input").on("input", function() {
		var pwd = $(this).val().trim();
		for(var i = 0, len = pwd.length; i < len; i++) {
			$input.eq("" + i + "").val(pwd[i]);
		};
		$input.each(function() {
			var index = $(this).index();
			if(index >= len) {
				$(this).val("");
			}
		});
		if(len == 4) {
			//执行其他操作  
		};
	});
}

function gotosure() {
	var num2 = $('#pwd-input').val();
	if(num2) {
		if(num2 == num) {
			window.location.href = "newPassport.html?UserID="+empcode
		} else {
			$("#hint").html("验证码输入错误")
			$("#pwd-input").val("")
			$(".fake-box_change input").val("")
		};
	} else {
		$("#hint").html("请输入验证码")
	};
};
var num;

function submit_verify() {
	var num1 = (Math.random() * 9).toFixed(0).toString();
	var num2 = (Math.random() * 9).toFixed(0).toString();
	var num3 = (Math.random() * 9).toFixed(0).toString();
	var num4 = (Math.random() * 9).toFixed(0).toString();
	num = num1 + num2 + num3 + num4;
	var subdata;
	subdata = '<?xml version="1.0" encoding="utf-8"?>';
	subdata += '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
	subdata += '<soap:Body>';
	subdata += '<GetVerfyMsg xmlns="http://tempuri.org/">';
	subdata += '<empcode>' + empcode + '</empcode>';
	subdata += '<msgcode>' + num + '</msgcode>';
	subdata += '</GetVerfyMsg>';
	subdata += '</soap:Body>';
	subdata += '</soap:Envelope>';
	$.ajax({
//		http://hn.kukahome.com/WebserviceHR/WebserviceHR.asmx
		"url": "http://drpapi.kukahome.com:8099/Lookfor/trans",
		"type": 'POST',
		"dataType": 'text',
		"data": {data:subdata,SOAPAction:"http://tempuri.org/GetVerfyMsg"},
		"success": function(data) {
			var msg = $(data).find("GetVerfyMsgResult").text()
			msg = JSON.parse(msg)
			if(msg.error != 0) {
				$("#hint").html(msg.msg)
				$("#pwd-input").val("")
				$(".fake-box_change input").val("")
			} else {
				$("#pwd-input").val("")
				$(".fake-box_change input").val("")
				$("#hint").html(msg.msg)
			}
			if(msg.error == 1) {
				$("#pwd-input").val("")
				$(".fake-box_change input").val("")
				$("#hint").html("同一号码修改太多次了")
			}
		},
		"error": function(data) {
			$("#hint").html("网络出问题了")
		},
		headers: {
//			Accept: "XML",
			"Content-Type": 'application/x-www-form-urlencoded',
//			"SOAPAction": "http://tempuri.org/GetVerfyMsg",
		}
	});
};